package com.example;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @since 通过反射忽略泛型
 */
public class TestReflection {
    public static void main(String[] args) {
        List<String> strs = new ArrayList<>();
        strs.add("hello");
        strs.add("world");
        Class clazz = strs.getClass();
        try {
            Method method = clazz.getMethod("add", Object.class);
            method.invoke(strs, 1);
            method.invoke(strs, new Date());
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } finally {
            for (Object obj : strs) {
                System.out.println(obj);
            }
            System.exit(0);
        }
    }
}





